package org.jiamandan.com.utils;


import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.jiamandan.com.constant.BizConstant;
import org.jiamandan.com.dto.JsyBasicDto;

import java.util.Calendar;
import java.util.Date;

/**
 * @version Revision 1.0.1
 * @版权：版权所有 (c) 2021
 * @author:Jmd

 * @see:
 * @创建日期：2023-05-08 13:57
 * @功能说明：
 * @begin
 * @修改记录:
 * @修改后版本 修改人        修改内容
 * @2023-05-08 13:57	         Jmd        	创建
 * @end
 */
public class JsyObjectUtil {

    public static JsyBasicDto parse(String payload) {
        String[] payloads = StringUtils.split(payload, BizConstant.separator1);
        String[] startItems = StringUtils.split(payloads[0], BizConstant.separator);
        String[] endItems = StringUtils.split(payloads[1], BizConstant.separator);
        JsyBasicDto dto = new JsyBasicDto();
        dto.setStartPrefix(StringUtils.substring(startItems[0], 0, 1));
        dto.setCmd(StringUtils.substring(startItems[0], 1, startItems[0].length()));
        dto.setDeviceNo(payloads[1].substring(0,15));
        dto.setData(payloads[1].substring(16,payloads[1].length()));
        return dto;
    }

    public static String currentDateTime() {
        Date current = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(current);
        int weakNum = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return DateUtil.format(current, "yyyy/MM/dd/HH/mm/ss") + "/" + StringUtils.leftPad(weakNum + "", 2, '0');
    }
}
